package com.learn.test;

import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextLine()) {
            long num = Long.parseLong(scanner.nextLine().trim());
            long diff = 1;
            long left = isSymmetric(num - diff);
            long right = isSymmetric(num + diff);
            while(left == -1 && right == -1) {
                diff++;
                left = isSymmetric(num - diff);
                right = isSymmetric(num + diff);
            }
            System.out.println(left > 0? left: right);
        }

    }

    /**
     * 测试是不是回文数
     * @param num 传入的数字
     * @return 返回值为-1时，表示不是回文数，是回文数的话返回传入的数字
     */
    private static long isSymmetric(long num) {
        String strNum = String.valueOf(num);
        int left = 0, right = strNum.length() - 1;
        while (left < right) {
            if(strNum.charAt(left) != strNum.charAt(right)) {
                return -1;
            }
            left++;
            right--;
        }
        return num;
    }
}
